home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GameSpring.as < prev    next >
Text File  |  2006-11-29  |  2KB  |  65 lines

  1. class GameSpring extends SSObject
  2. {
  3.    var assetID = "spring";
  4.    var strength = 1200;
  5.    var momentumTransfer = 0;
  6.    var time = 0;
  7.    var editor_isItem = true;
  8.    var editor_name = "Spring";
  9.    var editor_canRotate = true;
  10.    var editor_args_names = ["angle","strength"];
  11.    var editor_args_values = [0,GameSpring.prototype.strength];
  12.    var editor_args_types = ["number","number"];
  13.    var editor_args_options = [[-360,360,1],[0,5000,20]];
  14.    var editor_args_descriptions = ["",""];
  15.    var editor_args_mode = [0,0];
  16.    var editor_args_component = ["NumericStepper","NumericStepper"];
  17.    function GameSpring(angle, strength)
  18.    {
  19.       super();
  20.       this.addEvent("rotate",this.onRotate);
  21.       if(strength != null)
  22.       {
  23.          this.strength = Number(strength);
  24.       }
  25.       this.setAngle(!angle ? this.angle : angle);
  26.    }
  27.    function onAddToWorld()
  28.    {
  29.       this.zone = new SSZone(SSZone.SPHERE,this.radius,this.zone_onCollide,this);
  30.       this.world.addObject(this.zone);
  31.       this.onMove();
  32.    }
  33.    function onMove()
  34.    {
  35.       this.zone.moveTo(this.x + 20 * this.direction.x,this.y + 20 * this.direction.y,this.z);
  36.    }
  37.    function onRotate(angle)
  38.    {
  39.       var _loc2_ = angle * 3.141592653589793 / 180;
  40.       this.direction = new Vector(Math.sin(_loc2_),- Math.cos(_loc2_),0);
  41.       this.onMove();
  42.    }
  43.    function zone_onCollide(obj)
  44.    {
  45.       if(this.time + 0.1 > this.world.time)
  46.       {
  47.          return undefined;
  48.       }
  49.       this.time = this.world.time;
  50.       GameSound.playSound("Spring");
  51.       obj.jumpTime = 0;
  52.       obj.velocity.x = this.direction.x * (this.strength + obj.velocity.x * this.momentumTransfer);
  53.       obj.velocity.y = this.direction.y * (this.strength + obj.velocity.y * this.momentumTransfer);
  54.       return GDK.Node.COLLISION_CANCEL;
  55.    }
  56.    function editor_onDisplay(target, external)
  57.    {
  58.       target._rotation = this.angle;
  59.       target.clear();
  60.       target.lineStyle(0,52479);
  61.       var _loc3_ = this.strength - (1 - Math.log(this.strength) / 8) * this.strength * 3;
  62.       target.lineTo(0,- _loc3_);
  63.    }
  64. }
  65.